import { dns } from "@/pages/dns.js";

class HTTP{
	request(params){
		if(!params.method){
			params.method = "GET"
		}
		wx.request({
			method: params.method,
			url: dns + params.url,
			data: params.data,
			header: {
				'content-type': 'application/x-www-form-urlencoded',
				'token': uni.getStorageSync("token")
			},
			success:(res)=>{
				console.log(res);
				let code = res.data.code.toString();
				if(code.startsWith('2')){
					params.success(res);
				};
				if(code.startsWith('1')){
					uni.showModal({
					    title: '提示',
					    content: '当前未登录或登录失效,是否重新登陆?',
					    success: function (res) {
					        if (res.confirm) {
								uni.switchTab({
									url: '/pages/me/index'
								})
					        } else if (res.cancel) {
					            console.log('用户点击取消');
					        }
					    }
					});
				};
				if(code.startsWith('5')){
					uni.showToast({
						icon: 'none',
						title: res.data.msg
					})
				}
			}
		})
	}
}
export { HTTP }